package com.imooc.distributedemo.resume.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * leetcode118 杨辉三角
 */
public class Solution118 {
    public static void main(String[] args) {
        int n = 5;
        List<List<Integer>> result = generate(n);
        System.out.println(result);
    }

    public static List<List<Integer>> generate(int numRows) {
        int row = numRows,col=numRows;
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> listFirst = new ArrayList<>();
        listFirst.add(1);
        result.add(listFirst);
        // 后续的数组
        for (int i = 1; i < numRows; i++) {
            List<Integer> list = new ArrayList<>();
            list.add(1); // 每一行第一个数据都是1
            // 处理中建数据
            List<Integer> previousRow = result.get(i-1);
            for (int j = 1; j < i; j++) {
                int num = previousRow.get(j-1)+previousRow.get(j);
                list.add(num);
            }

            list.add(1); // 每一行最后一个数据都是1
            result.add(list);
        }

        /*List<List<Integer>> result = new ArrayList<>();
        if(numRows<=1){
            int[] a = {1};
            List<Integer> list = (List)Arrays.asList(a);
            result.add(list);
            return result;
        }else{

            for (int i = 1; i < numRows; i++) {
                List<Integer> list = fab(i);
            }
        }*/
        return result;
    }

    private static List<Integer> fab(int i) {
        if(i==1){
            int[] a = {1};
            List<Integer> list = (List)Arrays.asList(a);
            return list;
        }else if(i==2){
            int[] a = {1,1};
            List<Integer> list = (List)Arrays.asList(a);
            return list;
        }else{
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < i; j++) {
                if(j==0||j==i-1){
                    list.add(1);
                }else{
                    ///int a = fab(j-1)+fab(j);
                }
            }
        }
        return null;
    }
}
